package com.example.learnandroid2;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = (Button) findViewById(R.id.Button);
    }

    //旧版
    public void onOldButtonClicked(View view) {
        //声明对象
        AlertDialog dialog;
        //绑定当前界面窗口，设置标题
        dialog = new AlertDialog.Builder(this).setTitle("旧版对话框")
                .setMessage("这是旧版的对话框，使用简单\n但是没有自动支持屏幕旋转！")          //设置提示信息
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(getApplicationContext(), "你确定了", Toast.LENGTH_SHORT).show();
                    }
                })
                //添加“确定”按钮
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(getApplicationContext(), "你取消了", Toast.LENGTH_SHORT).show();
                    }
                })   //添加“取消”按钮
                .create();      //创建对话框
        dialog.show();
    }

    //新版
    public void onSimpleButtonClicked(View view) {
        SimpleDialogFragment dialog = new SimpleDialogFragment();
        dialog.show(getSupportFragmentManager(), "simple");
    }

    //选择对话框
    public void onChoiceButtonClicked(View view) {
        ChoiceDialogFragment dialog = new ChoiceDialogFragment();
        dialog.setListener(new ChoiceDialogFragment.NotifyDialogListener() {
            @Override
            public void onDialogPositiveClicked(String gender) {
                Toast.makeText(getApplicationContext(), "你选对了：" + gender, Toast.LENGTH_SHORT).show();
            }
        });
        dialog.show(getSupportFragmentManager(), "choice");
    }

    //单选对话框
    public void onRadioButtonClicked(View view) {
        RadioDialogFragment dialog = new RadioDialogFragment();
        dialog.setListener(new RadioDialogFragment.NotifyDialogListener() {
            @Override
            public void onDialogPositiveClicked(String gender) {
                Toast.makeText(getApplicationContext(), "你选对了：" + gender, Toast.LENGTH_SHORT).show();
            }
        });
        dialog.show(getSupportFragmentManager(), "radiochoice");
    }

    //多选对话框
    public void onMulButtonClicked(View view) {
        MulchoiceDialogFragment dialog = new MulchoiceDialogFragment();
        dialog.setListener(new MulchoiceDialogFragment.NotifyDialogListener() {
            @Override
            public void onDialogPositiveClicked(String gender) {
                Toast.makeText(getApplicationContext(), "你选对了：" + gender, Toast.LENGTH_SHORT).show();
            }
        });
        dialog.show(getSupportFragmentManager(), "muliochoice");
    }
  /*  //自定义对话框
    public void onUdefineButtonClicked(View view){
        UserDefineDialogFragment dialog = new UserDefineDialogFragment();
        dialog.setListener(new UserDefineDialogFragment.NotifyDialogListener() {
            @Override
            public void onDialogPositiveClicked(String gender) {
                Toast.makeText(getApplicationContext(),"editTextName1"+editTextName1,Toast.LENGTH_SHORT).show();
            }
        });
        dialog.show(getSupportFragmentManager(),"choice");
    }
}*/
}